//
//  MachineListViewController.m
//  EPBPro
//
//  Created by wucha on 2018/6/14.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "MachineListViewController.h"
#import "MachineDetailViewController.h"
#import "MachineTableViewCell.h"
#import "HttpEquipmentAction.h"

@interface MachineListViewController ()
//@property (nonatomic,strong) NSArray *listArray;
@property (nonatomic,strong) NSString *status;
@property (nonatomic,strong) AreaInfo *areaInfo;

@end

@implementation MachineListViewController

-(id)initWithStatus:(NSString*)status withAreaInfo:(AreaInfo*)areaInfo{
    if (self == [super init]) {
        self.status = status;
        self.areaInfo = areaInfo;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleName = @"机器列表";
    self.tableView.separatorStyle = 0;
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadData];
}

//-(void)loadData{
//    EquipmentActionInfo *equipmentActionInfo = [[EquipmentActionInfo alloc] init];
//    equipmentActionInfo.status = self.status;
//    equipmentActionInfo.city = self.areaInfo.name;
//    [HttpEquipmentAction postEquipmentListWithAction:equipmentActionInfo block:^(id result, NSError *error) {
//        if (!error) {
//            self.listArray = result;
//            [self.tableView reloadData];
//        }
//    }];
//}

-(void)loadData{
    __weak MachineListViewController *filterView = self;
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [filterView loadHeader];
    }];
    header.lastUpdatedTimeLabel.hidden = YES;
    self.tableView.mj_header = header;
    
    [self.tableView.mj_header beginRefreshing];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadFooter)];
    
    EquipmentActionInfo *equipmentActionInfo = [[EquipmentActionInfo alloc] init];
    equipmentActionInfo.status = self.status;
    equipmentActionInfo.city = self.areaInfo.name;
    [self setClass:@"HttpEquipmentAction" action:@selector(postEquipmentListWithAction:block:) object:equipmentActionInfo];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.resultArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MachineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[MachineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    EquipmentInfo *equipmentInfo = self.resultArray[indexPath.row];
    [cell setMachineInfo:equipmentInfo];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    EquipmentInfo *equipmentInfo = self.resultArray[indexPath.row];
    MachineDetailViewController *machineDetailViewController = [[MachineDetailViewController alloc] initWithEquipmentInfo:equipmentInfo];
    [self.navigationController pushViewController:machineDetailViewController animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
